<template>
  <ul class="app-header-nav">
    <li class="item">
      <RouterLink class="link" to="/">首页</RouterLink>
    </li>
    <li class="item" v-for="item in list" :key="item.name" @mouseenter="show(item)">
      <router-link class="link" :to="'/category/' + item.id" @click="hide(item)">{{
        item.name
      }}</router-link>
      <!-- 弹出框 -->
      <div class="layer" :class="{active:item.open}">
        <ul v-for="sub in item.subCateGroupList" :key="sub.id">
          <h3>{{ sub.name }}</h3>
          <li v-for="ele in sub.categoryList" :key="ele.id">
            <a href="#">
              <img :src="ele.bannerUrl" :alt="ele.name" />
              <div>{{ ele.name }}</div>
            </a>
          </li>
        </ul>
      </div>
    </li>
  </ul>
</template>

<script>
import { computed } from "vue";
import { useStore } from "vuex";
export default {
  // eslint-disable-next-line no-unused-vars
  setup(props) {
    const store = useStore();
    //从仓库读取分类列表
    const list = computed(() => {
      return store.state.category.cateList;
    });
    const show = (item) => {
        item.open = true;
    };
    const hide = (item) => {
        item.open = false;
    };
    return { list ,show ,hide};
  },
};
</script>
<style scoped lang='less'>
.app-header-nav {
  position: relative;
  clear: both;
  z-index: 999;
  .item {
    float: left;
    padding: 0 10px;
    font-weight: bold;
    height: 40px;
    line-height: 40px;
    .link {
      padding-bottom: 7px;
      font-size: 15px;
    }
    // 鼠标划过高亮
    &:hover {
      .link {
        color: @xtxColor;
        border-bottom: 2px solid @xtxColor;
      }
      .layer {
        opacity: 1;
        height: 500px;
      }
      .active{
        opacity: 1;
      }
    }
  }
  .layer {
    position: absolute;
    left: 0;
    top: 42px;
    opacity: 0;
    background-color: #fff;
    box-shadow: 0 0 5px #ccc;
    width: 1100px;
    // height: 500px;
    height: 0;
    overflow: auto;
    transition: all 0.25s;
    ul {
        display: inline-table;
        text-align: center;
        width:15%;
      li {
        height: 100px;
        width: 110px;
        text-align: center;
        a {
          border-bottom: 0;
        }
        img {
          width: 50px;
          height: 50px;
          text-align: center;
        }
        &:hover {
          background-color: #f7f7f7;
        }
      }
    }
  }
}
</style>